import useAccountTokenInfoStore from '@/core/account/store/useAccountTokenInfoStore'
import { isNil } from 'lodash-es'
import UnauthorizedError from '@/core/framework/error/UnauthorizedError'
import Oauth2TokenInfoDto from '@/core/oauth2/types/model/dto/Oauth2TokenInfoDto'

class AuthManager {
	// 获取并且检查用户账户token是否过期
	getAndCheckUserTokenInfo = (): Oauth2TokenInfoDto => {
		const accountTokenInfo = useAccountTokenInfoStore.getState()
		if (isNil(accountTokenInfo) || isNil(accountTokenInfo.accessToken)) {
			throw new UnauthorizedError()
		}
		return accountTokenInfo
	}
}

const manager = new AuthManager()

export default manager
